package yxy.apple.util;

public class Sequencer {
	private int minimum = Integer.MIN_VALUE;
	private int maximum = Integer.MAX_VALUE;
	private int index = 0;

	public Sequencer() {
		this(0, Integer.MAX_VALUE);
	}

	public Sequencer(int minimum, int maximum) {
		this.minimum = minimum;
		this.maximum = maximum;
		this.index = this.minimum;
	}

	public synchronized int next() {
		if (index >= this.maximum) {
			this.index = this.minimum;
		}
		int result = this.index;
		this.index++;
		return result;
	}

	public synchronized int current() {
		return this.index;
	}

	public synchronized void reset() {
		this.index = this.minimum;
	}
}
